class EmpleadosController < ApplicationController
  # GET /empleados
  # GET /empleados.xml
  def index
    @empleados = Empleado.all
    @color
    @contcolor=0
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @empleados }
    end
  end

  # GET /empleados/1
  # GET /empleados/1.xml
  def show
    @empleado = Empleado.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @empleado }
    end
  end

  # GET /empleados/new
  # GET /empleados/new.xml
  def new
    @empleado = Empleado.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @empleado }
    end
  end

  # GET /empleados/1/edit
  def edit
    @empleado = Empleado.find(params[:id])
  end

  # POST /empleados
  # POST /empleados.xml
  def create
    @empleado = Empleado.new(params[:empleado])

    respond_to do |format|
      if @empleado.save
        format.html { redirect_to(@empleado, :notice => 'Empleado was successfully created.') }
        format.xml  { render :xml => @empleado, :status => :created, :location => @empleado }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @empleado.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /empleados/1
  # PUT /empleados/1.xml
  def update
    @empleado = Empleado.find(params[:id])

    respond_to do |format|
      if @empleado.update_attributes(params[:empleado])
        format.html { redirect_to(@empleado, :notice => 'Empleado was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @empleado.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /empleados/1
  # DELETE /empleados/1.xml
  def destroy
    @empleado = Empleado.find(params[:id])
    @empleado.destroy

    respond_to do |format|
      format.html { redirect_to(empleados_url) }
      format.xml  { head :ok }
    end
  end

  
   def empleado_sesion
    @email=params['openid.ext1.value.email']
    empleado = Empleado.find(:first, :conditions => [" correo = ?", @email ])
    if empleado
     session[:empleado_correo] = empleado.correo
     session[:empleado_nombre] = empleado.nombre + " " + empleado.apellido
     session[:empleado_id] = empleado.id
     session[:type] = empleado.rol

    else
     flash[:notice] = " El email \"" + @email + "\" no esta registrado!"
     redirect_to :controller => 'application', :action => 'home'
    end
  end

 #Metodo que Finaliza la sesion del empleado
  def empleado_logout
    session[:empleado_correo] = nil
    session[:empleado_id] = nil
    session[:empleado_nombre]= nil
    session[:type] = nil

    redirect_to :controller => 'application', :action => 'home'
       flash[:notice] = 'Se ha terminado la sesion'
  end


  def empleado_google
        redirect_to "https://www.google.com/accounts/o8/ud
?openid.ns=http://specs.openid.net/auth/2.0
&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0
&openid.ns.max_auth_age=300
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select
&openid.return_to=http://"+local_ip+":3000/empleado_sesion
&openid.realm=http://"+local_ip+":3000/empleado_sesion
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ui.ns=http://specs.openid.net/extensions/ui/1.0
&openid.ui.mode=popup
&openid.ui.icon=true
&openid.ns.ax=http://openid.net/srv/ax/1.0
&openid.ax.mode=fetch_request
&openid.ax.type.email=http://axschema.org/contact/email
&openid.ax.required=email"
  end

end
